"""
json.dump()  写入数据
json.load()  加载数据

"""


import json

file_name = "013_1.json"


def json_test_1():

    numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    with open(file_name, "w", encoding='UTF-8') as f:
        json.dump(numbers, f)

    with open(file_name, "r", encoding='UTF-8') as f:
        json_data = json.load(f)

    print(json_data)




def try_get_stored_username():
    try:
        with open(file_name, "r", encoding='UTF-8') as f:
            data = json.load(f)
    except FileNotFoundError:
        return None
    else:
        return data

def save_username():
    username = try_get_stored_username()
    print(username)
    if username is not None:
        print(f"Hey {username} is You!!!")
    else:
        username = input("Tell me what's your name? ")
        with open(file_name, "w", encoding='UTF-8') as f:
            json.dump(username, f)

save_username()

